<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>新的静态方法</h1>
    <ul>
        <li>Object.is(obj1,obj2)：判断两个对象是否相等，作用大体和===一样</li>
        <li>Object.assgin(resultObj,...targetObj)：把后面的对象列表合并到第一个对象中，并返回第一个对象的引用。</li>
        <li>Object.fromEntries()：把键值对数组的数组转为对象</li>
    </ul>
    <script>
        let r = Object.is("1",1);
        console.log("r = ",r); // false

        r = Object.is({},{})
        console.log("r = ",r); // false

        r = Object.is(null,undefined);
        console.log("null == undefined",null == undefined); // true
        console.log("r = ",r); // false

        console.log(Object.is(NaN,NaN)); // true
        console.log("NaN == NaN",NaN == NaN); // false

        console.log(Object.is(+0,-0)); // false
        console.log("+0 == -0",+0 == -0); // true
        console.log("+0 === -0",+0 === -0); // true


        console.log("-------------Object.assgin()-----------------")
        // Object.assgin()：合并对象(浅拷贝实现)
        let obj1 = {};
        let obj2 = {name: "罗佰君",friend: {name: "胡正"}};
        let obj3 = {sex: "男"};

        let obj4 = Object.assign(obj1,obj2,obj3); // 把obj2,obj3合并到obj1中，并返回obj1
        console.log(obj4 == obj1);
        console.log(obj1);
        obj2.friend.name = "杜明均";
        console.log(obj1);

        console.log("-------------Object.fromEntries()-----------------")
        let arr = [["name","奉先"],["sex","男"]];
        let obj5 = Object.fromEntries(arr);
        console.log("obj5 = ",obj5);

        let map = new Map(arr);
        console.log("map = ",map);
        let obj6 = Object.fromEntries(map);
        // 也可以写成下面这样
        // let obj6 = Object.fromEntries(map.entries());
        console.log("obj6 = ",obj6);
    </script>
</body>
</html>